<?php

namespace plugin\laoha\app\model;

use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphOne;
use plugin\laoha\app\model\AttachUrl;

class Cate extends Base
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'ha_cates';

    
    protected $casts = [
        'ext' => 'json',
    ];       

    
    protected static function booted()
    {        
        static::creating(function ($model) {
            if(empty($model->is_publish)){
                $model->groups = '';
            }
            if(empty($model->parent_id)){
                $model->parent_id = 0;
            }
        });           
    }   


    public function posts(): HasMany
    {
        return $this->hasMany(Post::class);
    }
    
}
